﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CoolCode
{
    public class XException : Exception, IValidatingMessage
    {
        private string _message;

        public override string Message
        {
            get
            {
                return _message?? base.Message ;
            }
        }

        public string Code { get; protected set; }

        public string ParamName { get; protected set; }

        public virtual MessageType Type { get; protected set; }

        public object[] ExtraData { get; protected set; }

        public XException()
            : this(MessageType.Error,"" , "E0013")
        {
        }

        public XException(MessageType type, string paramName, string code, params  object [] extraData):base()
        {
            this.Type = type;
            this.Code = code;
            this.ParamName = paramName;
            this.ExtraData = extraData;
        }

        public void Retrieve(string message)
        {
            if (this.ExtraData != null && this.ExtraData.Length >0)
            {
                _message = string.Format(message, this.ExtraData);
            }
            else
            {
                _message = message;
            }
        }

    }

    public class ErrorException : XException
    {
        public ErrorException( string paramName,string code, params  object[] extraData)
            : base(MessageType.Error,paramName, code,  extraData )
        { 
        }
    }
}
